/**

 @Name：用户管理
 @Author：xuqipeter
 @Site：http://blog.xuziyu.cn/
    
 */

layui.define(function (exports) {
  layui.use(['table', 'layer', 'm-utils', 'form', 'admin', 'view', 'WithdrawalModel'], function () {
    var $ = layui.$,
      table = layui.table,
      layer = layui.layer,
      admin = layui.admin,
      view = layui.view,
      form = layui.form,
      setter = layui.setter,
      baseUrl = setter.baseUrl,
      utils = layui['m-utils'],
      widthdrawalModel = layui.WithdrawalModel;

    form.render();
    widthdrawalModel.tableList = widthdrawalModel._tableList()
    /* search重载table */
    form.on('submit(js-btn-table-search)', function (data) {
      let field = data.field;
      widthdrawalModel.tableList.reload({
        where: field
      });
      return false;
    });
    /*监听主页面table行工具栏*/
    var tableObj;
    table.on('tool(tableList)', function (obj) {
      tableObj = obj;
      const data = obj.data;
      const layEvent = obj.event;
      const tr = obj.tr;
      switch (layEvent) {
        case 'success':
          _layerSuccess(tableObj);
          break;
        case 'fail':
          _layerFail(tableObj);
          break;
      }
    });
    /* 通过 */
    function _layerSuccess(obj) {
      const data = obj.data;
      layer.confirm(`确定要通过吗？`, {
        icon: 3
      }, function (confirmIdx) {
        let fieldData = {
          account_withdraw_id: data.account_withdraw_id,
          status: 'success'
        }
        widthdrawalModel._doWithdraw({
          fieldData
        })
        layer.close(confirmIdx);
      })
    }
    /* 驳回 */
    function _layerFail(obj) {
      const data = obj.data
      layer.confirm(`确定要驳回吗？`, {
        icon: 3
      }, function (confirmIdx) {
        layer.prompt({
          formType: 2,
          title: '提现驳回的备注',
          area: ['400px', '200px'], //自定义文本域宽高
        }, function (value, index, elem) {
          let fieldData = {
            account_withdraw_id: data.account_withdraw_id,
            status: 'failure',
            note: value
          }
          widthdrawalModel._doWithdraw({
            fieldData
          })
          layer.close(index);
        });

        layer.close(confirmIdx);
      })
    }
    /* 提交表单 */
    form.on('submit(submitBtn)', function (res) {
      let data = utils.formDataFilter(res.field) || '';
      layer.msg('操作成功', {
        icon: 1,
        itme: 1500
      })
      layer.close(orderModel.layerFull)
      return false;
    })

  })

  exports('m-withdrawal', {})
})